import { request } from "@/utils/request";
import type {
  DeleteParams,
  RoleParams,
  QueryParams,
  QueryResult,
  RelationParams,
  QueryRelationResult,
} from "./typing";
import type { PageResult, ResponseBody } from "@/api/typing";

/**分页查询角色 */
export const queryByPage = (params: QueryParams) => {
  return request.get<QueryParams, ResponseBody<PageResult<QueryResult>>>(
    "/role/page",
    {
      params,
    }
  );
};

/**新增角色 */
export const add = (params: RoleParams) => {
  return request.post<RoleParams, ResponseBody>("/role/add", params);
};

/**修改角色 */
export const update = (params: RoleParams) => {
  return request.put<RoleParams, ResponseBody>("/role/update", params);
};

/**删除角色 */
export const del = (params: DeleteParams) => {
  return request.delete<DeleteParams, ResponseBody>("/role/delete", {
    params,
  });
};

/**查询角色关系 */
export const queryRelation = (roleId: string) => {
  return request.get<string, ResponseBody<QueryRelationResult>>(
    "/role/relation/list",
    {
      params: { roleId },
    }
  );
};

/**修改角色关系 */
export const updateRelation = (params: RelationParams) => {
  return request.put<RelationParams, ResponseBody>(
    "/role/relation/update",
    params
  );
};

/**查询所有角色 */
export const queryByList = () => {
  return request.get<null, ResponseBody<QueryResult[]>>("/role/list");
};

/**列表查询当前用户关联的角色 */
export const queryUserRoleList = () => {
  return request.get<null, ResponseBody<QueryResult[]>>("/role/user/list");
};
